home *** CD-ROM | disk | FTP | other *** search
/ Programming in Microsoft Windows with C# / Programacion en Microsoft Windows con C#.iso / Codigo / Cuadros de diálogo / BetterFontAndColorDialogs / BetterFontAndColorDialogs.cs next >
Encoding:
Text File  |  2002-05-23  |  2.1 KB  |  65 lines

  1. //--------------------------------------------------------
  2. // BetterFontAndColorDialogs.cs ⌐ 2001 by Charles Petzold
  3. //--------------------------------------------------------
  4. using System;
  5. using System.Drawing;
  6. using System.Windows.Forms;
  7.  
  8. class BetterFontAndColorDialogs:Form
  9. {
  10.      protected ColorDialog clrdlg = new ColorDialog();
  11.  
  12.      public static void Main()
  13.      {
  14.           Application.Run(new BetterFontAndColorDialogs());
  15.      }
  16.      public BetterFontAndColorDialogs()
  17.      {
  18.           Text = "Dißlogos Fuente y Color mejorados";
  19.  
  20.           Menu = new MainMenu();
  21.           Menu.MenuItems.Add("&Formato");
  22.           Menu.MenuItems[0].MenuItems.Add("&Fuente...",
  23.                                         new EventHandler(MenuFontOnClick));
  24.           Menu.MenuItems[0].MenuItems.Add("&Color de fondo...",
  25.                                         new EventHandler(MenuColorOnClick));
  26.      }
  27.      void MenuFontOnClick(object obj, EventArgs ea)
  28.      {
  29.           FontDialog fontdlg = new FontDialog();
  30.  
  31.           fontdlg.Font  = Font;
  32.           fontdlg.Color = ForeColor;
  33.           fontdlg.ShowColor = true;
  34.           fontdlg.ShowApply = true;
  35.           fontdlg.Apply += new EventHandler(FontDialogOnApply);
  36.  
  37.           if(fontdlg.ShowDialog() == DialogResult.OK)
  38.           {
  39.                Font = fontdlg.Font;
  40.                ForeColor = fontdlg.Color;
  41.                Invalidate();
  42.           }
  43.      }
  44.      void MenuColorOnClick(object obj, EventArgs ea)
  45.      {
  46.           clrdlg.Color = BackColor;
  47.  
  48.           if (clrdlg.ShowDialog() == DialogResult.OK)
  49.                BackColor = clrdlg.Color;
  50.      }
  51.       void FontDialogOnApply(object obj, EventArgs ea)
  52.      {
  53.           FontDialog fontdlg = (FontDialog) obj;
  54.  
  55.           Font = fontdlg.Font;
  56.           ForeColor = fontdlg.Color;
  57.           Invalidate();
  58.      }
  59.     protected override void OnPaint(PaintEventArgs pea)
  60.      {
  61.           Graphics grfx = pea.Graphics;
  62.           grfx.DrawString("íHola, cuadros de dißlogo comunes!", Font, 
  63.                           new SolidBrush(ForeColor), 0, 0);
  64.      }
  65. }